package net.angrynut.web.handler.controller;

import com.google.common.collect.ImmutableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class DemoForActuatorController {

    @Autowired
    private GaugeService gaugeService;

    @Autowired
    private CounterService counterService;

    /**
     * 先调用一次此接口，再调用 `/metrics` 即可看到这里加的 `my.active.metric1` 的值。
     *
     * 这是主动设置 metric 的值。
     */
    @RequestMapping("/demo/custom/metrics")
    public Map demoCustomMetrics() {
        gaugeService.submit("my.active.metric1", 12);
        counterService.increment("my.active.metric2");
        return ImmutableMap.of("Hello", "Metrics");
    }
}
